//Given a string columnTitle that represents the column title as appear in an Ex
//cel sheet, return its corresponding column number. 
//
// For example: 
//
// 
//A -> 1
//B -> 2
//C -> 3
//...
//Z -> 26
//AA -> 27
//AB -> 28 
//...
// 
//
// 
// Example 1: 
//
// 
//Input: columnTitle = "A"
//Output: 1
// 
//
// Example 2: 
//
// 
//Input: columnTitle = "AB"
//Output: 28
// 
//
// Example 3: 
//
// 
//Input: columnTitle = "ZY"
//Output: 701
// 
//
// Example 4: 
//
// 
//Input: columnTitle = "FXSHRXW"
//Output: 2147483647
// 
//
// 
// Constraints: 
//
// 
// 1 <= columnTitle.length <= 7 
// columnTitle consists only of uppercase English letters. 
// columnTitle is in the range ["A", "FXSHRXW"]. 
// 
// Related Topics 数学 
// 👍 223 👎 0


package leetcode.editor.cn;

import org.junit.Assert;

//Java：Excel Sheet Column Number
 class P171ExcelSheetColumnNumber{
    public static void main(String[] args) {
        Solution solution = new P171ExcelSheetColumnNumber().new Solution();
        // TO TEST
        Assert.assertEquals(solution.titleToNumber("AB"), 28);
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int titleToNumber(String columnTitle) {
        int sum = 0;
        for (int i = 0; i < columnTitle.length(); i++) {
            char c = columnTitle.charAt(i);
            //Input: columnTitle = "AB" 28
            sum *= 26;
            sum += (c - 'A') + 1;
        }
        return sum;

    }
}
//leetcode submit region end(Prohibit modification and deletion)

}